<template>
  <a-modal @ok="ok" okText="确定" cancelText="取消"
           :visible="visible" @cancel="close" title="新建权限">
    <Row label="权限名称">
      <a-input v-model="actionName" placeholder="请输入权限名称"/>
    </Row>
    <Row label="操作类型">
      <a-select v-model="actionType" placeholder="请选择操作类型">
        <a-select-option v-for="item in actionTypes" :value="item.value">
          {{ item.title }}
        </a-select-option>
      </a-select>
    </Row>
  </a-modal>
</template>
<script>
import Row from '@/components/hhd/design/FormDesigner/base/Row.vue';
import {actionTypes} from '@/components/hhd/design/Constants';
import {createProps} from '@/utils';
import ActionUtils from '@/components/hhd/design/FormAction/ActionUtils';
import {createDefaultAction} from '@/components/hhd/design/FormDesigner/types';

export default {
  name: 'FormActionModal',
  components: {Row},
  props: {
    formDefinition: createProps(Object, () => undefined),
  },
  data() {
    return {
      actionTypes,
      actionName: undefined,
      actionType: undefined,
      visible: false
    };
  },
  methods: {
    open() {
      this.visible = true;
    },
    close() {
      this.visible = false;
      this.actionName = undefined;
      this.actionType = undefined;
    },
    createAction() {
      return createDefaultAction(this.formDefinition, this.actionName, this.actionType, false)
    },
    ok() {
      if (!this.actionName || !this.actionType) {
        this.$message.error('权限名称和操作类型不能为空');
        return;
      }
      this.$emit('ok', this.createAction());
      this.close();
    },
  }
};
</script>